/**
 * Created by aa on 2016/8/25.
 */
'use strict';
var utils = require('../common/utils');
var cac = utils.cac;

//图片轮播
const RECEIVE_TAB1_SLIDER_ITEMS = 'RECEIVE_TAB1_SLIDER_ITEMS';
//华康产品
const RECEIVE_REGULAR_PROFIT_PRODUCTS = 'RECEIVE_REGULAR_PROFIT_PRODUCTS';
const RECEIVE_FLOAT_PROFIT_PRODUCTS = 'RECEIVE_FLOAT_PROFIT_PRODUCTS';
const RECEIVE_REGULARANDFLOAT_PROFIT_PRODUCTS = 'RECEIVE_REGULARANDFLOAT_PROFIT_PRODUCTS';
//公募基金
const RECEIVE_RAISEFUNDS = 'RECEIVE_RAISEFUNDS';

var receiveRaiseFunds;

//对外暴露变量
exports.RECEIVE_TAB1_SLIDER_ITEMS = RECEIVE_TAB1_SLIDER_ITEMS;
exports.RECEIVE_REGULAR_PROFIT_PRODUCTS = RECEIVE_REGULAR_PROFIT_PRODUCTS;
exports.RECEIVE_FLOAT_PROFIT_PRODUCTS = RECEIVE_FLOAT_PROFIT_PRODUCTS;
exports.RECEIVE_REGULARANDFLOAT_PROFIT_PRODUCTS = RECEIVE_REGULARANDFLOAT_PROFIT_PRODUCTS;
exports.RECEIVE_RAISEFUNDS = RECEIVE_RAISEFUNDS;


exports.receiveTab1SliderItems = cac(RECEIVE_TAB1_SLIDER_ITEMS, 'tab1SliderItems');
exports.receiveRegularProfitProducts = cac(RECEIVE_REGULAR_PROFIT_PRODUCTS, 'regularProfitProducts');
exports.receiveFloatProfitProducts = cac(RECEIVE_FLOAT_PROFIT_PRODUCTS, 'floatProfitProducts');
exports.receiveRegularAndFloatProfitProducts = cac(RECEIVE_REGULARANDFLOAT_PROFIT_PRODUCTS, 'regularAndFloatProfitProducts');
exports.receiveRaiseFunds = receiveRaiseFunds = cac(RECEIVE_RAISEFUNDS, 'raiseFunds');


//对外暴露方法

//分页获取基金列表
exports.getFundsList = (currentPage, pageSize, fundType, orderByType,fundCode)=> {
    if (fundType === undefined) {
        fundType = -1;
    }
    if (orderByType === undefined) {
        orderByType = 1;
    }
    if(fundCode==undefined){
        fundCode='';
    }
    return (dispatch, getState) => {
        reqwest({
            url: '/api/fundInfoList',
            method: 'post',
            contentType: 'application/json',
            data: fundType == -1?JSON.stringify({
                orderByType: orderByType,
                curPage: currentPage,
                pageSize: pageSize,
                fundCode:fundCode
            }):JSON.stringify({
                orderByType: orderByType,
                fundType: fundType,
                curPage: currentPage,
                pageSize: pageSize,
                fundCode:fundCode
            })
        })
            .then(function (data) {
                if (data.status == 200) {
                    dispatch(receiveRaiseFunds(data));
                }
            })
            .fail(function (err, msg) {
                alert('获取数据出错');
            })
    }
};

//根据父标id获取所有
exports.getListByParId = (parId, callBack)=> {
    if (parId === undefined) {
        return;
    }
    return (dispatch, getState) => {
        reqwest({
            url: '/api/getListByParId?parId=' + parId,
            method: 'get',
            contentType: 'application/json'
        })
            .then(function (data) {
                callBack(data);
            })
            .fail(function (err, msg) {
                alert('获取数据出错');
            })
    }
};

